package com.itheima.algorithm;

public class SelectionSort {
    public static void main(String[] args) {
        //选择排序
        int[] arr = {5,3,6,8,1,7,9,4,2};

        for (int i = 0; i < arr.length - 1; i++) {
            int minPos = i;
            for (int j = i + 1; j < arr.length; j++) {
                //minPos = arr[j] < arr[minPos] ? j : minPos;
                if(arr[j] < arr[minPos])
                    minPos = j;
            }
            System.out.println("minPos:" + minPos);

            int temp = arr[i];
            arr[i] = arr[minPos];
            arr[minPos] = temp;
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
